﻿using System;
using System.Collections.Generic;
using System.ComponentModel.DataAnnotations;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace HCQ2_Model.DocModel.APIParam
{
    /// <summary>
    /// 购物车下单参数
    /// </summary>
    public class PlaceAnOrderParam:BaseParam, IValidatableObject
    {
        /// <summary>
        /// 商品ID数组
        /// </summary>
        [Required(ErrorMessage = "请选择购物车中的商品")]
        public int[] CommodityId;

        public IEnumerable<ValidationResult> Validate(ValidationContext validationContext)
        {
            PlaceAnOrderParam param = validationContext.ObjectInstance as PlaceAnOrderParam;
            if (param.CommodityId == null)
            {
                yield return new ValidationResult("请选择购物车中的商品", new string[] { "CommodityId" });
            }
            else
            {
                if (param.CommodityId.Length == 0)
                {
                    yield return new ValidationResult("请选择购物车中的商品", new string[] { "CommodityId" });
                }
            }
        }
    }
}
